<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="选择店铺" prop="storeId">
        <el-select v-model="queryParams.storeId" class="width4" placeholder="请选择店铺"
                   clearable filterable>
          <el-option v-for="(dict,index) in storeList" :key="index" :label="dict.storeAlias+' - '+dict.storeName"
                     :value="dict.storeId"/>
        </el-select>
      </el-form-item>
      <el-form-item label="测评订单状态" prop="status">
        <el-select v-model="queryParams.status" clearable>
          <el-option v-for="item in dict.type.evaluation_status" :key="item.value" :label="item.label"
                     :value="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="sellerStoreProductEvaluationList" @selection-change="handleSelectionChange"
              border :row-class-name="tableRowClassName">
      <el-table-column type="selection" width="40" align="center"/>
      <el-table-column label="店铺名称" align="center" prop="storeName"/>
      <el-table-column label="卖家全称" align="center" prop="sellerSignerFullname"/>
      <el-table-column label="国家" align="center" prop="country">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_evaluation_country" :value="scope.row.country"></dict-tag>
        </template>
      </el-table-column>
      <el-table-column label="产品主图" align="center" prop="productImg">
        <template slot-scope="scope">
          <imagePreview :src="scope.row.productImg" width="50px" height="50px"/>
        </template>
      </el-table-column>
      <el-table-column label="SKU" align="center" prop="skuCode"/>
      <el-table-column label="购买链接" show-overflow-tooltip align="center" prop="link"/>
      <el-table-column label="测评数量" align="center" prop="number" width="75"/>
      <el-table-column show-overflow-tooltip label="关键词" align="center" prop="keyWord"/>
      <el-table-column label="测评时间" align="center" prop="evaluationTime">
        <template slot-scope="scope">
          <span>{{ scope.row.evaluationTime }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.evaluation_status" :value="scope.row.status"></dict-tag>
        </template>
      </el-table-column>
      <el-table-column label="留言" align="center" prop="leaveInfo"/>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                @pagination="getList"/>
  </div>
</template>

<script>
import {selectAutoEvaluationList} from "@/api/autoOperation";
import {selectAllStore} from "@/api/autoOperation/evaluation";

export default {
  name: "SellerStoreProductEvaluation",
  dicts: ['evaluation_status', 'sys_evaluation_country'],
  data() {
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 在线商品测评表格数据
      sellerStoreProductEvaluationList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        skuCode: undefined,
        status: undefined,
        storeId: undefined
      },
      storeList: [],//店铺列表
    };
  },
  created() {
    this.getList();
    this.getEmpowerList()
  },
  methods: {
    tableRowClassName({row, rowIndex}) {
      // if (row.type == '2' || row.type == '3') {
      //   return 'warning-row';
      // }
    },
    // 获取自动化店铺
    getEmpowerList() {
      selectAllStore({userId: this.$store.getters.userId}).then(res => {
        this.storeList = res.data;
      });
    },
    /** 查询在线商品测评列表 */
    getList() {
      this.loading = true;
      selectAutoEvaluationList(this.queryParams).then(response => {
        this.sellerStoreProductEvaluationList = response.rows;
        let list = response.rows;
        for (let i = 0; i < list.length; i++) {
          if (list[i].totalAmount) {
            list[i]['isEditTotalAmount'] = false
          } else {
            list[i]['isEditTotalAmount'] = true
          }
        }
        this.total = response.total;
      }).finally(() => {
        this.loading = false;
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
  }
};
</script>
<style>
.el-table .warning-row {
  background: #fabfbf;
}

.el-table .success-row {
  background: rgb(0, 255, 187);
}
</style>
